home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
FromTheMag
/
JW FLV MEDIA PLAYER 4.2
/
mediaplayer.exe
/
player.swf
/
scripts
/
com
/
jeroenwijering
/
player
/
Model.as
< prev
next >
Wrap
Text File
|
2008-11-04
|
10KB
|
312 lines
package com.jeroenwijering.player
{
import com.jeroenwijering.events.ControllerEvent;
import com.jeroenwijering.events.ModelEvent;
import com.jeroenwijering.events.ModelStates;
import com.jeroenwijering.models.CameraModel;
import com.jeroenwijering.models.HTTPModel;
import com.jeroenwijering.models.ImageModel;
import com.jeroenwijering.models.RTMPModel;
import com.jeroenwijering.models.SoundModel;
import com.jeroenwijering.models.VideoModel;
import com.jeroenwijering.models.YoutubeModel;
import com.jeroenwijering.utils.Draw;
import com.jeroenwijering.utils.Stretcher;
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLRequest;
import flash.system.LoaderContext;
public class Model extends EventDispatcher
{
public var config:Object;
private var thumb:Loader;
private var image:String;
private var controller:Controller;
private var models:Object;
private var currentModel:String;
private var currentURL:String;
public var skin:MovieClip;
public function Model(param1:Object, param2:MovieClip, param3:Controller)
{
super();
config = param1;
if(config["streamscript"])
{
config["streamer"] = config["streamscript"];
}
skin = param2;
Draw.clear(skin.display.media);
controller = param3;
controller.addEventListener(ControllerEvent.ITEM,itemHandler);
controller.addEventListener(ControllerEvent.MUTE,muteHandler);
controller.addEventListener(ControllerEvent.PLAY,playHandler);
controller.addEventListener(ControllerEvent.PLAYLIST,playlistHandler);
controller.addEventListener(ControllerEvent.QUALITY,qualityHandler);
controller.addEventListener(ControllerEvent.RESIZE,resizeHandler);
controller.addEventListener(ControllerEvent.SEEK,seekHandler);
controller.addEventListener(ControllerEvent.STOP,stopHandler);
controller.addEventListener(ControllerEvent.VOLUME,volumeHandler);
thumb = new Loader();
thumb.contentLoaderInfo.addEventListener(Event.INIT,thumbHandler);
skin.display.addChildAt(thumb,skin.display.getChildIndex(skin.display.media));
models = new Object();
}
private function thumbLoader() : void
{
var _loc1_:String = null;
_loc1_ = playlist[config["item"]]["image"];
if(_loc1_ && _loc1_ != image)
{
image = _loc1_;
thumb.load(new URLRequest(_loc1_),new LoaderContext(true));
}
}
private function volumeHandler(param1:ControllerEvent) : void
{
if(currentModel)
{
models[currentModel].volume(param1.data.percentage);
}
}
private function qualityHandler(param1:ControllerEvent) : void
{
if(currentModel)
{
models[currentModel].quality(param1.data.state);
}
}
public function get playlist() : Array
{
return controller.playlist;
}
private function thumbHandler(param1:Event) : void
{
var evt:Event = param1;
try
{
Bitmap(thumb.content).smoothing = true;
}
catch(err:Error)
{
}
resizeHandler();
}
public function mediaHandler(param1:DisplayObject = undefined) : void
{
Draw.clear(skin.display.media);
skin.display.media.addChild(param1);
resizeHandler();
}
private function playlistHandler(param1:ControllerEvent) : void
{
if(currentModel)
{
stopHandler();
}
else
{
sendEvent(ModelEvent.STATE,{"newstate":ModelStates.IDLE});
}
thumbLoader();
}
private function loadModel(param1:String) : void
{
switch(param1)
{
case "camera":
models[param1] = new CameraModel(this);
break;
case "image":
models[param1] = new ImageModel(this);
break;
case "sound":
if(config["streamer"] && config["streamer"].substr(0,4) == "rtmp")
{
models[param1] = new RTMPModel(this);
}
else
{
models[param1] = new SoundModel(this);
}
break;
case "video":
if(config["streamer"])
{
if(config["streamer"].substr(0,4) == "rtmp")
{
models[param1] = new RTMPModel(this);
}
else
{
models[param1] = new HTTPModel(this);
}
}
else
{
models[param1] = new VideoModel(this);
}
break;
case "youtube":
models[param1] = new YoutubeModel(this);
}
}
private function stopHandler(param1:ControllerEvent = undefined) : void
{
currentURL = undefined;
if(currentModel)
{
models[currentModel].stop();
}
sendEvent(ModelEvent.STATE,{"newstate":ModelStates.IDLE});
}
private function playHandler(param1:ControllerEvent) : void
{
if(currentModel)
{
if(param1.data.state == true)
{
models[currentModel].play();
}
else
{
models[currentModel].pause();
}
}
}
private function muteHandler(param1:ControllerEvent) : void
{
if(currentModel && param1.data.state == true)
{
models[currentModel].volume(0);
}
else if(currentModel && param1.data.state == false)
{
models[currentModel].volume(config["volume"]);
}
}
private function seekHandler(param1:ControllerEvent) : void
{
if(currentModel)
{
models[currentModel].seek(param1.data.position);
}
}
private function itemHandler(param1:ControllerEvent) : void
{
var _loc2_:String = null;
var _loc3_:String = null;
_loc2_ = playlist[param1.data.index]["type"];
_loc3_ = playlist[param1.data.index]["file"];
if(models[_loc2_] && _loc2_ == currentModel)
{
if(_loc3_ == currentURL && _loc2_ != "rtmp")
{
models[_loc2_].seek(playlist[param1.data.index]["start"]);
}
else
{
models[_loc2_].stop();
currentURL = _loc3_;
models[_loc2_].load();
}
}
else
{
if(currentModel)
{
models[currentModel].stop();
}
if(!models[_loc2_])
{
loadModel(_loc2_);
}
currentModel = _loc2_;
currentURL = _loc3_;
models[_loc2_].load();
}
thumbLoader();
}
public function sendEvent(param1:String, param2:Object) : void
{
var _loc3_:String = null;
if(param1 == ModelEvent.STATE && param2.newstate != config["state"])
{
switch(param2.newstate)
{
case ModelStates.IDLE:
case ModelStates.COMPLETED:
sendEvent(ModelEvent.TIME,{
"position":playlist[config["item"]]["start"],
"duration":playlist[config["item"]]["duration"]
});
thumb.visible = true;
skin.display.media.visible = false;
break;
case ModelStates.BUFFERING:
case ModelStates.PLAYING:
_loc3_ = playlist[config["item"]]["file"].substr(-3);
if(_loc3_ != "aac" && _loc3_ != "mp3" && _loc3_ != "m4a")
{
thumb.visible = false;
skin.display.media.visible = true;
}
else
{
thumb.visible = true;
skin.display.media.visible = false;
}
}
param2.oldstate = config["state"];
config["state"] = param2.newstate;
dispatchEvent(new ModelEvent(param1,param2));
}
else if(param1 != ModelEvent.STATE)
{
dispatchEvent(new ModelEvent(param1,param2));
}
if(param1 == ModelEvent.META && param2.width)
{
resizeHandler();
}
}
private function resizeHandler(param1:ControllerEvent = null) : void
{
Stretcher.stretch(skin.display.media,config["width"],config["height"],config["stretching"]);
if(thumb.content && thumb.width > 0)
{
Stretcher.stretch(thumb,config["width"],config["height"],config["stretching"]);
}
}
}
}